$(document).ready(function() {
    // bind 'myForm' and provide a simple callback function
    $("div#shift a").click(shift_ajax);
    $("img#loader").hide();
    var options = { 
        beforeSubmit:  before,  // pre-submit callback 
        success:       after  // post-submit callback 
 
    };
    
    $('#myForm').ajaxForm(options); 

    $( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            Upload: function() {
                $('#myForm').submit();
            },
            Cancel: function() {
                $("img#loader").hide("");
                $( this ).dialog( "close" );
            }
        },
        close: function() {
             $("img#loader").hide("");
            $("#myForm input").val('');
        }
    });
    $( "#create-user" )
    .button({
        icons: {
            primary: "ui-icon-gear"
        }
    })
    .click(function() {
        $( "#dialog-form" ).dialog( "open" );
    });
});
function shift_ajax()
{
    var id = this.id;
   // alert(id);
    data = "appid="+id;
    $.ajax({
                type: 'POST',
                url: base_url() + 'user_profile/shift_ajax',
                data: data,
                datatype: 'json',
                success : function (result) {
                    var data=$.parseJSON(result);
                  //  alert(data.appid);
                    var html="Status: "+data.message+"\n"+
                  "Date of apply: "+data.applydate;
                                     
                  alert(html);
                    
                }
            });

}
function before()
{
    $("img#loader").fadeIn("slow");
}
function after(result)
{
    var file=result.toString();
    if(file.match("ERROR")!=null)
    {
        $("img#loader").fadeOut("slow");
        alert(file);
        
    }
    else
    {
        //alert(file);
       $("img#photo").get(0);
        var img=$("img#photo").get(0);
        img.src=base_url()+"user_images/"+file;
        $("img#loader").fadeOut("slow");
        $( "#dialog-form" ).dialog( "close" );
    }
}